package com.jlkf.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jlkf.pojo.TblOtherCourse;
import com.jlkf.pojo.TblVipInfo;
import com.jlkf.service.VipInfoService;
import com.platform.server.response.response.pojo.ReturnData;
import com.platform.server.util.StringTools;

@Controller
@RequestMapping("vip")
public class VipController {
	@Autowired
	private VipInfoService vipInfoService;
	
	@RequestMapping("getVipList")
	@ResponseBody
	public ReturnData getVipList(Integer pageNumber,Integer pageSize){
		PageHelper.startPage(pageNumber, pageSize);
		List<TblVipInfo> list = vipInfoService.getVipList();
		PageInfo<TblVipInfo> pageInfo = new PageInfo<>(list);
		return new ReturnData(list,pageInfo.getPages(),(int)pageInfo.getTotal(),200,"会员列表");
	}
	
	@RequestMapping("updateVipInfo")
	@ResponseBody
	public ReturnData updateVipInfo(@RequestBody String json){
		try{
			TblVipInfo info = StringTools.json2Obj(json, TblVipInfo.class);
			info.setgUpdatetime(new Date());
			int rel = vipInfoService.update(info);
			if(rel>0){
				return new ReturnData(200,"修改成功");
			}else{
				return new ReturnData(500,"修改失败");
			}
		}catch (Exception e) {
			e.printStackTrace();
			return new ReturnData("系统错误");
		}
	}
	
	/**
	 * 查看详情
	 */
	@RequestMapping("getDetail")
	@ResponseBody
	public ModelAndView getDetail(Long gId){
		TblVipInfo vipInfo = vipInfoService.getDetail(gId);
		ModelAndView andView = new ModelAndView();
    	andView.addObject("vipInfo",vipInfo);
    	andView.setViewName("jsp/vipManager/updateVip");
		return andView;
	}
	
}
